package com.ftg.learn.util;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
@Schema(name = "分页信息")
public class PageEx<T> {
    @Schema(description = "当前页")
    private int pageNum;
    @Schema(description = "每页数量")
    private int pageSize;
    @Schema(description = "总记录数")
    private Long total;
    @Schema(description = "总页数")
    private int totalPage;
    @Schema(description = "数据")
    private List<T> Rows;

    public static <T> PageEx<T> convertToPageEx(PageInfo<T> pageInfo) {
        PageEx<T> page = new PageEx<>();
        page.setPageNum(pageInfo.getPageNum());
        page.setPageSize(pageInfo.getPageSize());
        page.setTotal(pageInfo.getTotal());
        page.setTotalPage(pageInfo.getPages());
        page.setRows(pageInfo.getList());
        return page;
    }
}
